package comfour;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Demo2 {

    public static void main(String[] args) throws Exception {
        //数据库连接
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/kh62";
        String name="root";
        String password="123456";
        Connection connection = DriverManager.getConnection(url, name, password);
        System.out.println(connection);

        String sql=" insert into student(StudentName,LoginPwd,sex)value (?,?,?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,"ZSSSS");
        preparedStatement.setString(2,"123");
        preparedStatement.setInt(3,1);
        int i = preparedStatement.executeUpdate();
        if(i>0){
            System.out.println("添加成功");
        }
        preparedStatement.close();
        connection.close();

    }
}
